<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>老师</title>
    <style>
        #container {
            width: 80%;
            margin: 10px auto;
        }
        .teacher {
            width: 100%;
            margin: 0 auto;
            padding: 10px 0;
            border-bottom: 1px dashed gray;
            overflow: auto;
        }
        .teacher div {
            float: left;
        }
        .photo {
            height: 140px;
            border-radius: 75px;
            overflow: hidden;
            margin-left: 20px;
        }
        .info {
            width: 75%;
            margin-left: 30px;
        }
        .info div {
            clear: both;
            margin: 5px 10px;
        }
        .info span {
            margin-right: 25px;
        }
        .info a {
            text-decoration: none;
            color: blue;
        }
        .user {
            float: right;
            margin: 10px 10px;
        }
        .user+h1 {
            clear: both;
        }
        #photo {
            border-radius: 32px 32px 32px 32px;
        }
    </style>
</head>
<body>
	<div id='container'>
		<h1>{{ subject.name }}学科老师信息</h1>
		<hr>
		{% if teachers %}
		{% for teacher in teachers %}
		<div class='teacher'>
			<div class='photo'>
				<img src="{% static teacher.photo %}" height='140' alt="">
			</div>
			<div class='info'>
				<h3>{{ teacher.name }}</h3>
				<div class="intro">{{ teacher.detail }}</div>
				<div class="comment">
					<a href="praise/?tno={{ teacher.no }}">好评</a>
					(<span>{{ teacher.good_count }}</span>)
					<a href="criticize/?tno={{ teacher.no }}">差评</a>
					(<span>{{ teacher.bad_count }}</span>)
				</div>
			</div>
		</div>
    {% endfor %}
    {% else %}
    <h3>暂时没有该学科的老师信息</h3>
    {% endif %}
    <p>
        <a href="/vote/">返回首页</a>
    </p>
	</div>
	<!-- Ajax实现点赞刷新 -->
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script>
        $(() => {
            $('.comment>a').on('click', (evt) => {
                evt.preventDefault()
                let anchor = $(evt.target)
                let url = anchor.attr('href')
                $.getJSON(url, (json) => {
                    if (json.code == 10001) {
                        let span = anchor.next()
                        span.text(parseInt(span.text()) + 1)
                    } else if (json.code == 10003) {
                        location.href = '/vote/login/?backurl=' +
                            location.pathname + location.search
                    } else {
                        alert(json.hint)
                    }
                })
            })
        })
    </script>
</body>
</html>